const UserService = require('../services/user.service')

const userService = new UserService()

class UserController {
  async findAll (ctx, next) {
    const query = ctx.request.query
    const data = await userService.findAll(query)
    ctx.response.body = data
  }
  async findOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await userService.findOne(id)
    ctx.response.body = data[0]
  }
  async updateOne (ctx, next) {
    const id = ctx.request.params.id
    const body = ctx.request.body
    const data = await userService.updateOne(id, body)
    ctx.response.body = data
  }
  async deleteOne (ctx, next) {
    const id = ctx.request.params.id
    const data = await userService.deleteOne(id)
    ctx.response.body = data
  }
}

module.exports = UserController